#ifndef SERIALCOMMUNICATOR_H
#define SERIALCOMMUNICATOR_H

#include <termios.h>
#include "stdafx.h"
#include "RawData.h"

namespace Core {

    #define BAUDRATE B115200

    class SerialCommunicator
    {
        public:
            SerialCommunicator(std::string pDevice);
            virtual ~SerialCommunicator();
            void Open();
            void Close();

            void Write(std::string pContent);
            std::string Read(unsigned pLength);
            unsigned char ReadChar();
            void WriteChar(unsigned char pChar);

            int GetFD();

            int Read(RawData& pRawData , unsigned char pDelim);
            int Read(RawData& pRawData , unsigned int pLength);
            int Write(RawData& pRawData);
        protected:
        private:
            int mFileDescriptor;
            std::string mDevice;
            struct termios mOldOptions, mNewOptions;

            void Error();
    };
}

#endif // SERIALCOMMUNICATOR_H
